{extend name="public:base" /}
{block name="style"}
<link rel="stylesheet" type="text/css" href="__INDEX__/css/public.css">
<link rel="stylesheet" type="text/css" href="__INDEX__/css/style.css">
<link rel="stylesheet" type="text/css" href="__INDEX__/css/responsive.css">
<link rel="shortcut icon" href="__INDEX__/images/favorite.ico">
{/block}

{block name="html"}
{include file="index@public/main" /}
<div class="right_style">
    <h3 class="title_style"><em></em><span>个人信息</span></h3>
    <div id="user_info">
        <!--个人信息-->
         <form method="post" id="userFrom" action='{:url("User/edit_msg")}' enctype="multipart/form-data">
            <div class="Personal_info" id="Personal">
                <div class="uplaod">
                    <img id="imga" src="{$Arr.portrait}"  onerror='this.src="__INDEX__/images/touxiang.png"' onclick="document.getElementById('upfile').click()" class="touxiang" />
                    <input name="upfile" id="upfile" type="file" class="submitImage"  onchange="up_portrait(this,imga)"  />
                </div>
                <div class="xinxi form">
                   <!--  <form method="post" id="userFrom" action='{:url("User/edit_msg")}' enctype="multipart/form-data"> -->
                    <div class="group">
                        <label for="name">昵称：</label>
                        <input name="nickname" type="text"  value="{$Arr['nickname']? $Arr['nickname'] : ''}" id="nickname" class="name"  />
                    </div>
                    <div class="group">
                        <label for="name">账号：</label>
                        <input name="account" type="text"  value="{$Arr['account']? $Arr['account'] : ''}" id="account" class="name"  disabled/>
                    </div>
                    <div class="group">
                        <label for="tel">电话：</label> 
                        <input name="phone" type="tel" value="{$Arr['phone']? $Arr['phone'] : ''}" id="phone" class="tel" disabled/>
                    </div>
                    <div class="group">
                        <label for="oldpassword">旧密码：</label> 
                        <input name="old_pwd" id="old_pwd" type="password" value="" id="oldpassword" class="password"  />
                    </div>
                    <div class="group">
                        <label for="newpassword">新密码：</label> 
                        <input name="new_pwd" id="new_pwd" type="password" value="" class="newpassword" id="newpassword" />
                    </div>
                    <div class="group">
                        <label for="pay_password">支付密码：</label> 
                        {if condition="$Arr.is_pay eq 1"}
                        <input name="pay_pwd" type="password" value="" class="check pay_password" id="pay_pwd" placeholder="******" disabled/>
                        {else /}
                        <input name="pay_pwd" type="password" value="" class="check pay_password" id="pay_pwd" placeholder="设置支付密码"/>
                        {/if}
                        <input type="button" class="checkbtn" value="找回支付密码" onclick="window.location.href='pay_passd.html'"/>
                    </div>
                    <div class="bottom">
                        <input onclick="submitFrom()" type="button" value="确认修改" class="submit" />
                    </div>
                    <!-- </form> -->
                </div>

            </div>
        </form>
    </div>
</div>

{/block}

{/block}
{block name="javascript"}
<script src="__INDEX__/js/jquery-1.9.1.min.js"></script>
<script src="__INDEX__/js/layer/mobile/layer_mobile.js"></script>
<script src="__INDEX__/js/layer/mobile/layer.js"></script>
<script src="__INDEX__/js/public.js"></script>
<script src="__INDEX__/layer/layer.js"></script>
<script type="text/javascript">

    $('#old_pwd').change(function(){
        var old_pwd = $('#old_pwd').val();
        $.ajax({
            type: 'POST',
            url: '{:url("User/find_paw")}',
            dataType: 'json',
            data: {
                old_pwd: old_pwd,
            },
            success: function (data) {
                if( data.result != 0 ){
                    layer.open({
                        content: "请输正确的密码"
                        ,style: 'color:#fff;background-color:#da7276; border:none;'
                        ,time: 2000 //2秒后自动关闭
                    });
                    $('#old_pwd').val('');
                }
            }
        });
    })

    function submitFrom(){
        
        var nickname = $("#nickname").val();
        if( nickname == "" ){
            layer.open({
                content: "请输入你的昵称"
                ,style: 'color:#fff;background-color:#da7276; border:none;'
                ,time: 2000 //2秒后自动关闭
            });
            return false;
        }
        var old_pwd = $("#old_pwd").val();
        var new_pwd = $("#new_pwd").val();

        if(old_pwd.length > 0 && old_pwd != null){
            if(new_pwd.length == 0 || new_pwd.match(/^\d{6}$/) == null){
                layer.open({
                    content: "请输入6位以上新密码"
                    ,style: 'color:#fff;background-color:#da7276; border:none;'
                    ,time: 2000 //2秒后自动关闭
                });
                return false;
            }
        }
        if(new_pwd.length > 0 &&  new_pwd != null){
            if(old_pwd.length == 0){
                layer.open({
                    content: "请输入旧密码"
                    ,style: 'color:#fff;background-color:#da7276; border:none;'
                    ,time: 2000 //2秒后自动关闭
                });
                return false;
            }
        }
        var pay_pwd = $("#pay_pwd").val();
        if(pay_pwd.length > 0 && pay_pwd.match(/^\d{6}$/) == null){
            layer.open({
                content: "请输入6位支付密码"
                ,style: 'color:#fff;background-color:#da7276; border:none;'
                ,time: 2000 //2秒后自动关闭
            });
            return false;
        }
        $("#userFrom").submit();
    }


    function up_portrait(imgFile,img) {
        var filextension = imgFile.value.substring(imgFile.value.lastIndexOf("."), imgFile.value.length);
        filextension = filextension.toLowerCase();
        if ((filextension != '.jpg') && (filextension != '.gif') && (filextension != '.jpeg') && (filextension != '.png')) {
            alert("格式不正确！");
            imgFile.focus();
            var file = $('#upfile');
            file.after(file.clone().val(""));
            file.remove();
        } else {
            var path;
            var maxsize=2*1024*1024;
            if(imgFile.files[0].size>maxsize) {
                alert('文件大小不能超过2M');
                var file = $('#upfile');
                file.after(file.clone().val(""));
                file.remove();
                return false;
            }else {
                if (document.all) //IE
                {
                    imgFile.select();
                    path = document.selection.createRange().text;
                    $(img).attr('src', path);
                } else //FF
                {
                    path = window.URL.createObjectURL(imgFile.files[0]);
                    $(img).attr('src', path);
                    //$('#img1').attr('src', path);
                }
                return true;
            }
        }
    }
</script>

{/block}



